package img_ocr

import (
	"fmt"
	"goocr/data_treating"
	"goocr/util"
)

func ImgOcr() {
	site, err := data_treating.GetImgPath()
	if err != nil {
		util.LogError(fmt.Sprintf("获取图片目录出错:%v", err))
		return
	}
	rooms := handdleOcr(site)
	for _, room := range rooms {
		util.LogInfo(fmt.Sprintf("roomCode:%d", room.Code))
		for _, player := range room.Players {
			util.LogInfo(fmt.Sprintf("id:%d,nickname:%s,score:%d,captureTime:%v", player.Id, player.Nickname, player.Score, room.RomeTime))
			if room.RomeTime == nil {
				continue
			}
			//数据写入mysql
			data := &data_treating.User{
				UserId:      player.Id,
				RoomId:      room.Code,
				NickName:    player.Nickname,
				Score:       player.Score,
				CaptureTime: data_treating.GetUnix(room.RomeTime.Format(data_treating.DateTimeFormat)),
			}
			if err = data.Insert(); err != nil {
				util.LogError(fmt.Sprintf("数据写入出错:%v", err))
				return
			}
		}
	}
	util.LogInfo("数据全部写入成功")
}
